package com.changjiang.luban.config.exception;

import com.changjiang.luban.dao.domain.sys.SysLog;
import com.changjiang.luban.service.sys.LogServiceI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.io.IOException;

/**
 * ExceptionHandle
 * Description:
 *
 * @author nichangjiang@vip.qq.com
 * @version v0.1
 * @date 2018/6/20 - 11:10
 */
@SuppressWarnings("ALL")
@ControllerAdvice
public class ExceptionHandle {

    private final static Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);

    @Autowired
    private LogServiceI logServiceI;

    @ExceptionHandler(value = Exception.class)
    public void handle(Exception e){
        if (e instanceof FileUploadException){
            SysLog sysLog = SysLog.error("文件上传异常");
            logServiceI.saveLog(sysLog);
        }else if (e instanceof IOException){
            SysLog sysLog = SysLog.error("文件上传异常");
            logServiceI.saveLog(sysLog);
        }else {
            logger.info("[系统异常]{}",e);
        }

    }

}
